/*
 * Copyright (c) 2021 bestechnic (Shanghai) Technologies CO., LIMITED.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef __IOT_MAIN_H__
#define __IOT_MAIN_H__

#include "ext_dev_if.h"

#define CONFIG_TASK_DEFAULT_PRIOR 20 // default task priority

#define CN_EVENT_ERROR (1 << 31)
#define CN_SENSOR_EVENT_NONE (0)
#define CN_IR_EVENT (1 << 1)
#define CN_IR_COUNT_EVENT (1 << 2)
#define CN_KEY_EVENT (1 << 3)
#define CN_SENSOR_EVENT_ALL (CN_IR_EVENT | CN_KEY_EVENT | CN_IR_COUNT_EVENT)

#define CN_CONTROL_EVENT_NONE (0)
#define CN_BEEP_EVENT (1 << 4)
#define CN_LOCK_EVENT (1 << 5)
#define CN_CONTROL_EVENT_ALL (CN_BEEP_EVENT | CN_LOCK_EVENT)

#define CN_UI_EVENT_NONE (0)
#define CN_UI_BEEP_EVENT (1 << 6)
#define CN_UI_WIFI_EVENT (1 << 7)
#define CN_UI_DOOR_BELL_STATUS_EVENT (1 << 8)
#define CN_UI_EVENT_ALL (CN_UI_BEEP_EVENT | CN_UI_WIFI_EVENT | CN_UI_DOOR_BELL_STATUS_EVENT)

#define CN_APP_EVENT_NONE (0)
#define CN_APP_BEEP_EVENT (1 << 6)
#define CN_APP_LOCK_EVENT (1 << 7)
#define CN_APP_DOOR_BELL_STATUS_EVENT (1 << 8)
#define CN_APP_EVENT_ALL (CN_APP_BEEP_EVENT | CN_APP_LOCK_EVENT | CN_APP_DOOR_BELL_STATUS_EVENT)

#define APP_RET_SUCCESS 0
#define APP_RET_FAILED -1

typedef enum
{
    NO_PERSON_APPROACH = 0,
    CALLING_BELL,
    UNKNOWN_PERSON_APPROACH
} DoorBellStatusDef;

typedef struct {
    int irTriggerSecond;
    osEventFlagsId_t sensorEvent;
    osTimerId_t irTriggerTimerHandle;
    ExtDevIrMontStsDef extDevIrMontSts;
    ExtDevKeyMontStsDef extDevKeyMontSts;
    DoorBellStatusDef doorBellStatusTmp;
} SensorController;

typedef struct {
    osEventFlagsId_t driverEvent;
    osTimerId_t lockOpenTimerHandle;
    ExtDevLedIdDef extDevLedId;
    ExtDevLedActDef extDevLedAct;
    ExtDevBeepActDef extDevBeepAct;
} DriverController;

typedef enum
{
    LOCK_OPEN = 0,
    LOCK_CLOSE
} LockStatusDef;

typedef enum
{
    WIFI_ST_NOT_BIND = 0,
    WIFI_SIGNAL_LEVEL_1,
    WIFI_SIGNAL_LEVEL_2,
    WIFI_SIGNAL_LEVEL_3,
    WIFI_SIGNAL_LEVEL_4
} WifiStatusDef;

typedef struct {
    osEventFlagsId_t appEvent;
    LockStatusDef lockStatus;
    WifiStatusDef wifiStatus;
    ExtDevBeepActDef beepStatus;
    DoorBellStatusDef doorBellStatus;
} ApplicationController;

#endif // __IOT_MAIN_H__
